/*0GI1xcoeligdpMeXoHBphhVCrhxcviGrDnphTJgmfcwMg4RNPBhEzXRaezj70QBs*/
import ampub from 'ampub';
const { commonConst } = ampub;
const { StatusUtils } = commonConst;
const { UISTATE } = StatusUtils;

/**
 * 表格操作按钮
 * @param {*} props 
 * @param {*} key 
 * @param {*} text 
 * @param {*} record 
 * @param {*} index 
 */
export default function(props, key, text, record, index, tableId) {
	switch (key) {
		// 展开
		case 'Extend':
			openCard.call(this, props, record, index, tableId);
			break;
		// 删行
		case 'DelLine':
			delLine.call(this, props, index, tableId);
			break;
		// 复制行
		case 'CopyLine':
			copyLine.call(this, props, index, tableId, record);
			break;
		default:
			break;
	}
}

/**
 * 表格行展开
 * @param {*} props 
 * @param {*} record 
 * @param {*} index 
 */
function openCard(props, record, index, tableId) {
	let status = props.cardTable.getStatus(tableId);
	if (status == UISTATE.edit) {
		props.cardTable.setClickRowIndex(tableId, { record, index });
		props.cardTable.openModel(tableId, status, record, index);
	} else if (status == UISTATE.browse) {
		props.cardTable.toggleRowView(tableId, record);
	}
}

/**
 * 表格行删除
 * @param {*} props 
 * @param {*} index 
 */
function delLine(props, index, tableId) {
	props.cardTable.delRowsByIndex(tableId, index);
}

/**
 * 表格行复制
 * @param {*} props 
 * @param {*} index 
 */
function copyLine(props, index, tableId, record) {
	let newRecord = JSON.parse(JSON.stringify(record || {}));
	//复制行时需要清空表体主键及pseudocolumn
	if (newRecord.values) {
		if (newRecord.values.pk_newasset_b) {
			newRecord.values.pk_newasset_b = { value: null, display: null };
		}
		if (newRecord.values.pseudocolumn) {
			newRecord.values.pseudocolumn = { value: null };
		}
	}
	props.cardTable.insertRowsAfterIndex(tableId, newRecord, index);
}

/*0GI1xcoeligdpMeXoHBphhVCrhxcviGrDnphTJgmfcwMg4RNPBhEzXRaezj70QBs*/